//
//  XLAnchorEvaluateVC.m
//  XiangLove
//
//  Created by 李传坤 on 2018/8/3.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLAnchorEvaluateVC.h"
#import "XLTgLabelView.h"
@interface XLAnchorEvaluateVC ()
@property (nonatomic,strong) NSDictionary *dicData;
@property (nonatomic,strong) UILabel *number;
@property (nonatomic,strong) UILabel *goodPercent;
@property (nonatomic,strong) UILabel *middlePercent;
@property (nonatomic,strong) UILabel *badPercent;
@property (nonatomic,strong) UIView *gooline2;
@property (nonatomic,strong) UIView *middleline2;
@property (nonatomic,strong) UIView *badline2;
@property (nonatomic,strong) UIView *viewBiaoqian;
@property (nonatomic, strong) XLTgLabelView *labelView;
@property (strong, nonatomic)NSArray *GoodtittleArray;
@property (strong, nonatomic)NSMutableArray *GoodButtonArray;

@end

@implementation XLAnchorEvaluateVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showBackButton:NULL];
    self.navigationItem.title = @"服务评价";
    _GoodButtonArray = [[NSMutableArray alloc]init];
    UIView *topBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 180)];
//    topBackView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:topBackView];
    
    UIImageView *emojiImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 45, 24, 24)];
    emojiImage1.image = [UIImage imageNamed:@"video_icon_pj3_s"];
    [topBackView addSubview:emojiImage1];
    UIImageView *emojiImage2 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 95, 24, 24)];
    emojiImage2.image = [UIImage imageNamed:@"video_icon_pj2_s"];
    [topBackView addSubview:emojiImage2];
    UIImageView *emojiImage3 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 145, 24, 24)];
    emojiImage3.image = [UIImage imageNamed:@"video_icon_pj1_s"];
    [topBackView addSubview:emojiImage3];
    _number = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 25)];
    _number.text = @"评价人数:";
    
    //百分比
    [topBackView addSubview:_number];
    _goodPercent = [[UILabel alloc]initWithFrame:CGRectMake(40, 45, 40, 25)];
    _goodPercent.text = @"%";
    [topBackView addSubview:_goodPercent];
    
    _middlePercent = [[UILabel alloc]initWithFrame:CGRectMake(40, 95, 40, 25)];
    _middlePercent.text = @"%";
    [topBackView addSubview:_middlePercent];
    _badPercent = [[UILabel alloc]initWithFrame:CGRectMake(40, 145, 40, 25)];
    _badPercent.text = @"%";
    [topBackView addSubview:_badPercent];
    
    _goodPercent.font = _middlePercent.font = _badPercent.font = [UIFont systemFontOfSize:14];
    
    //百分比的线
    UIView *gooline1 = [[UIView alloc]initWithFrame:CGRectMake(80, 54, ScreenWidth-90, 5)];
    gooline1.layer.cornerRadius = 2.5;
    gooline1.layer.borderWidth = 0.5; gooline1.layer.borderColor = RGB_HEX(0xffbb01).CGColor;
    [topBackView addSubview:gooline1];
    _gooline2 = [[UIView alloc]initWithFrame:CGRectMake(80, 55, ScreenWidth-90, 3)];
    _gooline2.layer.cornerRadius = 2.5;; _gooline2.backgroundColor = RGB_HEX(0xffbb01);
    [topBackView addSubview:_gooline2];
    
    
    UIView *middleline1 = [[UIView alloc]initWithFrame:CGRectMake(80, 104, ScreenWidth-90, 5)];
    middleline1.layer.cornerRadius = 2.5;
    middleline1.layer.borderWidth = 0.5; middleline1.layer.borderColor = RGB_HEX(0xffbb01).CGColor;
    [topBackView addSubview:middleline1];
    _middleline2 = [[UIView alloc]initWithFrame:CGRectMake(80, 105, ScreenWidth-90, 3)];
    _middleline2.layer.cornerRadius = 2.5;; _middleline2.backgroundColor = RGB_HEX(0xffbb01);
    [topBackView addSubview:_middleline2];
    
    
    UIView *badline1 = [[UIView alloc]initWithFrame:CGRectMake(80, 154, ScreenWidth-90, 5)];
    badline1.layer.cornerRadius = 2.5;
    badline1.layer.borderWidth = 0.5; badline1.layer.borderColor = RGB_HEX(0xffbb01).CGColor;
    [topBackView addSubview:badline1];
    _badline2 = [[UIView alloc]initWithFrame:CGRectMake(80, 155, ScreenWidth-90, 3)];
    _badline2.layer.cornerRadius = 2.5; _badline2.backgroundColor = RGB_HEX(0xffbb01);
    [topBackView addSubview:_badline2];
    
    
    _viewBiaoqian = [[UIView alloc]initWithFrame:CGRectMake(0, 180, ScreenWidth, 180)];
    [self.view addSubview:_viewBiaoqian];
    
    UILabel *badComment = [[UILabel alloc]initWithFrame:CGRectMake(10, 180, 220, 40)];
    badComment.text = @"收到的差评";
    [self.view addSubview:badComment];
    
    NSDictionary *dic = @{@"userId":[[XLAccountManager shareInstance]model].Id};
    @weakify(self)
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/api/v2/Comment/GetAllEvaluateRate" parameters:dic resultClass:nil] subscribeNext:^(id x) {
        @strongify(self)
        NSDictionary *dic = x;
        _dicData = dic;
        self.GoodtittleArray = [_dicData objectForKey:@"BadLabels"];
//        self.GoodtittleArray = @[@"好评率",@"评率会直接影",@"平台的曝光",@"光度",@"光",@"在平台的曝光度和",@"和主",@"ersdfsdas",@"接影响在平",@"接影响在",@"平台的曝光度和"];
        NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:_GoodtittleArray];
        _viewBiaoqian.frame = CGRectMake(0, 220, ScreenWidth, 45 * (self.GoodtittleArray.count/3  + 1));
        self.labelView = [[XLTgLabelView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, _viewBiaoqian.frame.size.height) andLabelArray:mutableArray];
        [self.labelView layoutIfNeeded];
        [_viewBiaoqian addSubview:_labelView];
        [self.labelView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_viewBiaoqian);
            make.left.right.equalTo(_viewBiaoqian);
            make.bottom.equalTo(_viewBiaoqian);
        }];
        UILabel *labelInfor1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 240 + _viewBiaoqian.frame.size.height, ScreenWidth - 20, 40)];
        labelInfor1.text = @"1.好评率会直接影响在平台的曝光度和主播等 级的提升，好评率越高会获得更多推荐位置。";
        labelInfor1.numberOfLines = 2;labelInfor1.font = [UIFont systemFontOfSize:14];
        [self.view addSubview:labelInfor1];
        UILabel *labelInfor2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 290 + _viewBiaoqian.frame.size.height, ScreenWidth - 20, 40)];
        labelInfor2.text = @"2.如果差评率过高会得到平台相应的处罚。";labelInfor2.font = [UIFont systemFontOfSize:14];
        labelInfor1.textColor = labelInfor2.textColor = kDarkGrayColor;
        [self.view addSubview:labelInfor2];

        [self updateData];
//        [self initBiaoqianGood];
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        
    }];
    
}
- (void)updateData{
    _number.text = [NSString stringWithFormat:@"总评价人数:%@",_dicData[@"TotalNum"]];
    _goodPercent.text = [NSString stringWithFormat:@"%.0f%%",[_dicData[@"GoodRate"] floatValue]*100];
    _middlePercent.text = [NSString stringWithFormat:@"%.0f%%",[_dicData[@"NormalRate"] floatValue]*100];
    _badPercent.text = [NSString stringWithFormat:@"%.0f%%",[_dicData[@"BadRate"] floatValue]*100];
    CGFloat float1 = [_dicData[@"GoodRate"] floatValue];
    CGFloat float2 = [_dicData[@"NormalRate"] floatValue];
    CGFloat float3 = [_dicData[@"BadRate"] floatValue];
    _gooline2.frame = CGRectMake(80, 55, (ScreenWidth-90)*float1, 3);
    _middleline2.frame = CGRectMake(80, 105, (ScreenWidth-90)*float2, 3);
    _badline2.frame = CGRectMake(80, 155, (ScreenWidth-90)*float3, 3);
    
    
}
- (void)initBiaoqianGood{//好评标签初始化
    NSInteger wdith = ScreenWidth / 3 - 12;
    NSInteger height = 40;
    for (NSInteger i = 0 ; i < _GoodtittleArray.count; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.cornerRadius = 3;
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [button setTitle:_GoodtittleArray[i] forState:UIControlStateNormal];
        if (i < 3) {
            button.frame = CGRectMake(i * wdith+2, 0, wdith-4, 26);
            [_GoodButtonArray addObject:button];
            [_viewBiaoqian addSubview:button];
        }else if (i < 6){
            button.frame = CGRectMake((i-3) * wdith+2, height, wdith-4, 26);
            [_GoodButtonArray addObject:button];
            [_viewBiaoqian addSubview:button];
        }else{
            button.frame = CGRectMake((i-6) * wdith+2, height*2, wdith-4, 26);
            [_GoodButtonArray addObject:button];
            [_viewBiaoqian addSubview:button];
        }
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
